package com.yytek.am.controller;

import java.util.List;

import com.yytek.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.am.domain.FmDef;
import com.yytek.am.service.IFmDefService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 告警定义Controller
 * 
 * @author yytek-iot
 * @date 2022-10-10
 */
@Api(value = "告警定义控制器", tags = {"告警定义管理"})
@RestController
@RequestMapping("/def")
public class FmDefController extends BaseController
{
    @Autowired
    private IFmDefService fmDefService;

    /**
     * 分页查询告警定义列表
     */
    @ApiOperation("分页查询告警定义列表")
    @RequiresPermissions("am:def:list")
    @GetMapping("/list")
    public TableDataInfo list(FmDef fmDef)
    {
        startPage();
        //查询创建人
        String userId = SecurityUtils.getUserId().toString();
        fmDef.setOperator(userId);
        List<FmDef> list = fmDefService.selectFmDefList(fmDef);
        return getDataTable(list);
    }

    /**
     * 导出告警定义列表
     */
    @ApiOperation("导出告警定义列表")
    @RequiresPermissions("am:def:export")
    @Log(title = "告警定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmDef fmDef)
    {
        List<FmDef> list = fmDefService.selectFmDefList(fmDef);
        ExcelUtil<FmDef> util = new ExcelUtil<FmDef>(FmDef.class);
        util.exportExcel(response, list, "告警定义数据");
    }

    /**
     * 获取告警定义详细信息
     */
    @ApiOperation("获取告警定义详细信息")
    @RequiresPermissions("am:def:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fmDefService.selectFmDefById(id));
    }

    /**
     * 新增告警定义
     */
    @ApiOperation("新增告警定义")
    @RequiresPermissions("am:def:add")
    @Log(title = "告警定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmDef fmDef)
    {
        return toAjax(fmDefService.insertFmDef(fmDef));
    }

    /**
     * 修改告警定义
     */
    @ApiOperation("修改告警定义")
    @RequiresPermissions("am:def:edit")
    @Log(title = "告警定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmDef fmDef)
    {
        return toAjax(fmDefService.updateFmDef(fmDef));
    }

    /**
     * 删除告警定义
     */
    @ApiOperation("删除告警定义")
    @RequiresPermissions("am:def:remove")
    @Log(title = "告警定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fmDefService.deleteFmDefByIds(ids));
    }
}
